<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <input type="hidden" id="id" name="id">
            <div class="form-group">
                <label class="col-md-2 control-label">用户名</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="用户名" type="text" name="username"
                           id="user"
                           data-bv-notempty="true"
                           data-bv-notempty-message="用户名 不能为空">
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-2 control-label">账号</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="自定义账号" type="text" name="account"
                           id="account"
                           data-bv-notempty="true"
                           data-bv-notempty-message="账号 不能为空">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">密码</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="App用户密码" type="text" name="password"
                           id="password">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">手机号</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="手机号" type="text" maxlength="11" name="phonenumber" id="phonenumber">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">年龄</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="用户年龄" type="text" maxlength="20" name="userage" id="userage">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">邮箱</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="邮箱" type="text" maxlength="50" name="useremail" id="useremail">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">设备绑定信息</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="设备绑定信息" type="text" maxlength="50" name="devices" id="devices">
                </div>
            </div>

            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='appUsers.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/jq.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/my/roles/role.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript" src="../../js/dict.js"></script>

	<script type="text/javascript">


	//initRoles();
	initData();
	function initData(){
		var id = getUrlParam("id");
		if(id !== ""){
			$.ajax({
				type : 'get',
				url : '/appusers/get/'+id,
				async : false,
				success : function(data) {
                    document.getElementById('id').value=data.id;
                    document.getElementById('user').value=data.username;
                    document.getElementById('account').value=data.account;
                    document.getElementById('phonenumber').value=data.phonenumber;
                    document.getElementById('devices').value=data.devices;
                    document.getElementById('useremail').value=data.useremail;
                    document.getElementById('password').value=data.password;
                    document.getElementById('userage').value=data.userage;
				}
			});
		}
	}
	
		$('#form').bootstrapValidator();
		
		function update() {
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();

			$.ajax({
				type : 'put',
				url : '/appusers/update',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function() {
                    layui.use('layer', function () {
                        layer = layui.layer;
                        layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                            location.href = "appUsers.html";
                        });
                    })

				}
			});
		}
		
	</script>
</body>
</html>